package android.slc.appbase.ui.vd;

import android.slc.box.core.property.DataChangeListener;
import javafx.scene.Scene;
import javafx.scene.layout.Region;

/**
 * 基础的详细盒子vm
 *
 * @author slc
 * @date 2020-08-25 16:13
 */
public class BaseAppVd<VB extends BaseAppVmBox> {
    protected Region contentView;
    protected VB vmBox;
    private final DataChangeListener<Scene> sceneChangeListener = (value) -> {
        if (!BaseAppVd.this.contentView.sceneProperty().isNotNull().getValue()) {
            clear();
        }
    };

    public void init(Region contentView, VB vmBox) {
        this.contentView = contentView;
        this.vmBox = vmBox;
        initView();
        initMustCondition();
    }

    protected void initView() {
        this.contentView.sceneProperty().addListener(sceneChangeListener);
    }

    protected void initMustCondition() {

    }

    private void clear() {
        onCleared();
    }

    protected void onCleared() {
        this.contentView.sceneProperty().removeListener(sceneChangeListener);
    }
}
